package com.mo.admin.api.menu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mo.admin.api.menu.domain.Menu;
import com.mo.admin.api.menu.domain.vo.MenuVO;
import com.mo.admin.api.menu.mapper.MenuMapper;
import com.mo.admin.api.menu.service.MenuService;
import com.mo.admin.api.menu.utils.MenuTreeUtils;
import com.mo.admin.common.Result;
import com.mo.admin.common.utils.RequestResponseUtils;
import com.mo.admin.security.utils.JWTConstant;
import com.mo.admin.security.utils.JWTUtils;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;

import java.util.List;

/**
 * @author Administrator
 * @description 针对表【sys_menu(系统菜单表)】的数据库操作Service实现
 * @createDate 2025-06-25 17:06:40
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu>
        implements MenuService {
    @Resource
    private JWTUtils jwtUtils;

    @Override
    public Result getMenuVOList() {
        List<MenuVO> menuVOS = MenuTreeUtils.genMenuVOTree(this.list());
        return Result.success(menuVOS);
    }

    @Override
    public Result getAuthMenuVOList() {
        HttpServletRequest request = RequestResponseUtils.getCurrentRequest();
        String token = request.getHeader(JWTConstant.AUTHORIZATION);
        String userId = jwtUtils.getSubject(token);
        List<Menu> authMenuList = this.baseMapper.getAuthMenuList(userId);

        List<MenuVO> menuVOS = MenuTreeUtils.genMenuVOTree(authMenuList);
        return Result.success(menuVOS);
    }
}




